package util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.Buffer;

public class ChatSocket {
		private Socket socket;
		private BufferedReader reader;
		private OutputStream out;

		public ChatSocket(Socket socket) {
			super();
			this.socket = socket;
			try {
				reader=new BufferedReader(new InputStreamReader(socket.getInputStream()));
				out=socket.getOutputStream();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		public void sendMsg(String msg){
			try {
				out.write((msg+"\n").getBytes());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		public String receiveMsg(){
			String line=null;
			try {
				line=reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return line;
		}
		public void close(){
			try {
				reader.close();
				out.close();
				socket.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
}
